package binarysearch.test441;

import org.junit.Test;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/13 12:45
 */
public class Solution2 {

    // 超时
    public int arrangeCoins(int n) {
        if (n == 0) return 0;
        if (n == 1) return 1;
        int l = 1, r = n;
        while (l < r) {
            int mid = (l + r + 1) >> 1;
            if (((n * (1 + n)) / 2) <= n) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        return l;
    }

    @Test
    public void test(){
        int i = arrangeCoins(3);
        System.out.println(i);
    }
}
